var OrdersModule = function () {

	//团队查询框初始化
	var handleEmployeeTree = function() {
		$('#empGroupTree').jstree({
			"conditionalselect" : function (node, event) {
			      return false;
			    },
			'plugins' : [ "wholerow", "radio", "types" ],
			'core' : {
				"themes" : {
					"responsive" : false
				},
				'data' : {
					"url" : ctx + "/orders/groupTree",
				}
			},
			'multiple':false,
			"three-state":false,
			"types" : {
				"default" : {
					"icon" : "fa fa-folder icon-warning icon-lg"
				},
				"file" : {
					"icon" : "fa fa-file icon-warning icon-lg"
				}
			}
		}).on("changed.jstree", function(e, data) {
			if(data.node.parent == '#'){
				$('#groupId').val(null);
				$('#groupName').val(null);
			}else{
				//更新团队ID
				var groupId = $('#groupId').val();
				if("" == groupId){
					$('#groupId').val(data.node.id);
				}else{
					if(groupId.indexOf(data.node.id) >= 0){
					}else{
						$('#groupId').val(groupId + "," + data.node.id);
					}
				}
				//更新团队名
				var groupName = $('#groupName').val();
				if("" == groupName){
					$('#groupName').val(data.node.text);
				}else{
					if(groupName.indexOf(data.node.text) >= 0){
					}else{
						$('#groupName').val(groupName + "," + data.node.text);
					}
				}
			}
        });
	};
    $("#investorName").autocomplete({
        source: function(query,process){
        	$.ajax({
            	"contentType":"application/json; charset=UTF-8",
                "dataType" : 'json',
                "type" : "POST",
                "url" : ctx + "/appointment/investor/"+query.term,
                "data" : {"matchCount":200},
                "success" : function(data){
                	var ebean = [];
                	var length = data.length >= 10 ? 10 : data.length;
                	for (var int = 0; int < length; int++) {
                		var temp = [];
                		temp.label = data[int].name;
                		temp.name = data[int].name;
                		temp.value = data[int].name;
                		ebean.push(temp);
            		}
                    return process(ebean);
                }
            })
        },
        search:function(event, ui){
        },
        select: function(event, ui) {
            $("#investorName").val(ui.item.name);
            var uistr =ui.item;
            // 阻止事件的默认行为
            event.preventDefault(); 
        }
    });
    $("input#investorName").focus(function(){
    	$(this).autocomplete("search", "TOTAL");
    	event.preventDefault(); 
    });
    $("input#investorName").blur(function(){
    	event.preventDefault(); 
    });
    $("#employeeName").autocomplete({
        source: function(query,process){
        	$.ajax({
            	"contentType":"application/json; charset=UTF-8",
                "dataType" : 'json',
                "type" : "POST",
                "url" : ctx + "/orders/employee/"+query.term,
                "data" : {"matchCount":200},
                "success" : function(data){
                	var ebean = []
                	var length = data.length >= 10 ? 10 : data.length;
                	for (var int = 0; int < length; int++) {
                		var temp = [];
                		temp.label = data[int].employeeName;
                		temp.value = data[int].employeeName;
                		ebean.push(temp);
            		}
                    return process(ebean);
                }
            })
        },
        search:function(event, ui){
        	console.log("searched!");
//        	$("#employeeId").val("");
        },
        select: function(event, ui) {
            $("#employeeName").val(ui.item.label);
            var uistr =ui.item;
            // 阻止事件的默认行为
            event.preventDefault(); 
        }
    });
    $("input#employeeName").focus(function(){
    	$(this).autocomplete("search", "TOTAL");
    	event.preventDefault(); 
    });
    $("input#employeeName").blur(function(){
    	event.preventDefault(); 
    });
    $("#productBriefName").autocomplete({
        source: function(query,process){
        	$.ajax({
            	"contentType":"application/json; charset=UTF-8",
                "dataType" : 'json',
                "type" : "POST",
                "url" : ctx + "/orders/product/"+query.term +"/0",
                "data" : {"matchCount":200},
                "success" : function(data){
                	var ebean = []
                	var length = data.length >= 10 ? 10 : data.length;
                	for (var int = 0; int < length; int++) {
                		var temp = [];
                		temp.label = data[int].briefName;
                		temp.value = data[int].briefName;
                		ebean.push(temp);
            		}
                    return process(ebean);
                }
            })
        },
        search:function(event, ui){
        },
        select: function(event, ui) {
            $("#productBriefName").val(ui.item.label);
            var uistr =ui.item;
            // 阻止事件的默认行为
            event.preventDefault(); 
        }
    });
    $("input#productBriefName").focus(function(){
    	$(this).autocomplete("search", "TOTAL");
    	event.preventDefault(); 
    });
    $("input#productBriefName").blur(function(){
    	event.preventDefault(); 
    });
    var editable = function () {

        return {
            init: function () {
            	//格式化金额
            	function fmoney(s, n) {  
            	   if(s == ""|| undefined == s){
            		   return "--";
            	   }
                   n = n > 0 && n <= 20 ? n : 2;  
                   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";//更改这里n数也可确定要保留的小数位  
                   var l = s.split(".")[0].split("").reverse(),  
                   r = s.split(".")[1];  
                   t = "";  
                   for(i = 0; i < l.length; i++ )  
                   {  
                      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");  
                   }
                   var str = t.split("").reverse().join("") + "." + r.substring(0,2);
                   return str;//保留2位小数  如果要改动 把substring 最后一位数改动就可  
                }
            	
            	//表格初始化
                var oTable = $('#ordersEditable').dataTable({
                    "lengthMenu": [
                        [10, 15, 20, 50],
                        [10, 15, 20, 50]
                    ],
                    "autoWidth":false,
                    "scrollX":true,
                    "displayLength": 10,
                    "language": {
                        "lengthMenu": "每页 _MENU_ 条记录",
                        "zeroRecords":"数据为空",
                        "paginate": {
                            "previous": "上一页",
                            "next": "下一页"
                        },
                        "info" : "从 _START_ 到  _END_ 条，总记录为 _TOTAL_ 条",    
                        "infoEmpty" : "记录数为0",
                    },
                    "columnDefs": [
						{
						    "data": null,
						    'sortable': false,
						    "defaultContent": "Edit",
						    "targets": [9]
						}            
                    ],
                    "columns": [
                        { "data": "contactNum" ,'sortable': false,"defaultContent": "" },
//                       { "data": "orderId" ,'sortable': false,"defaultContent": "" },
                       { "data": "investorName" ,'sortable': false,"defaultContent": "" },
                       { "data": "productBriefName" ,'sortable': false,"defaultContent": "" },
                       { "data": "orderAmount" ,'sortable': false,"defaultContent": "" },
//                       { "data": "groupName" ,'sortable': false,"defaultContent": "" },
                       { "data": "employeeName",'sortable': false,"defaultContent": "" },
                       { "data": "orderTime" ,'sortable': false,"defaultContent": "" },
                       { "data": "payTime" ,'sortable': false,"defaultContent": "" },
                       { "data": "state" ,'sortable': false,"defaultContent": "" },
                       { "data": "type" ,'sortable': false,"defaultContent": "" },
                   ],
                   "filter" : false,
                   "processing": false,
                   "serverSide": true,
                   "ajaxSource": ctx + "/orders/query",
                   "serverMethod": "post",
                   "fnRowCallback" : function(nRow, aData, displayIndex) {
                	   nRow.children[0].id = aData.id;
                	   nRow.children[1].id = aData.orderId;
                	   nRow.children[2].id = aData.uploadVoucher;
                	   var orderId = 
                		   "<center>" + aData.orderId + "</center>";
                	   var inverstor = 
                		   "<center>" + '<a href="'+ctx+'/investor/detail/' + aData.investorId + '">' + aData.investorName + "<br>" + aData.investorMobile + "</a>" +"</center>";
                	   var productBriefName = 
                		   "<center>" + '<a href="'+ctx+'/product/detail/' + aData.productId + '">' + aData.productBriefName + "</a>" + "</center>";
                	   var orderAmount = 
                		   "<center>"+ fmoney(aData.orderAmount) + "</center>";
                	   var groupName = "";
                	   if(aData.groupName != undefined && aData.groupName != ''){
                		   groupName = "<center>" + aData.groupName + "</center>";
                	   }else{
                		   groupName = "<center>--</center>";
                	   }
                	   var contactNum = "";
                	   if(aData.contactNum != undefined && aData.contactNum != ''){
                		   contactNum = "<center>" + aData.contactNum + "</center>";
                	   }else{
                		   contactNum = "<center>--</center>";
                	   }
                	   var employee = 
                		   "<center>" + aData.employeeName + "<br>工号：" + aData.employeeNo + "</center>";
                	   var orderTime = 
                		   "<center>" + aData.orderTime + "</center>";
                	   var payTime = "";
                	   if(aData.payTime == undefined){
                		   payTime = "<center>--</center>";
                	   }else{
	                	   payTime = "<center>" + aData.payTime + "</center>";
                	   }
                	   //1已支付2未支付3已赎回4部分支付5已取消6已完成
                	   var state = aData.state;
                	   var formatState = "";
                	   var operation = "";
                	   var typeDes = "";
                	   if(aData.type == 1){
                    	   typeDes = "<center>线下</center>";
                       }else{
                    	   typeDes = "<center>线上</center>";
                       }
                	   switch (state) {
		                	   case (1):
		                		   formatState = "<center>已支付</center>";
		                	   	   if (aData.offlinePay == true && aData.auditState != 3) {
		                	   		   operation = 
		                	   			   '<a class="detail fa fa-bars fa-lg pull-left" title="详情" href="javascript:;"></a>\
		                	   			   <a class="upload fa fa-upload fa-lg pull-left" title="上传线下打款凭证" href="javascript:;"></a>';
		                	   	   }else{
		                	   		   operation = 
		                	   			   '<a class="detail fa fa-bars fa-lg pull-left" title="详情" href="javascript:;"></a>'; 
		                	   	   }
		                           break;
		                       case (2):
		                    	   formatState = "<center>未支付</center>";
		                       		//TODO 是否允许线下支付，是否需要申请仅对前端做限制，后台是不是需要对未支付的订单也做限制，-
		                       		//同时后台未支付的订单是无法提交审核的，但是否需要对不需要申请但是允许线下支付的直接显示上传打款凭证按钮
		                       	   if (aData.offlineAudit == 1) {
		                       		   operation = 
			                			   '<a class="detail fa fa-bars fa-lg pull-left" title="详情" href="javascript:;"></a>\
			                			   <a class="cancle fa fa-times-circle-o fa-lg pull-left" title="取消订单" href="javascript:;"></a>\
		                       			   <a class="offlineAudit fa fa-check-square-o fa-lg pull-left" title="审核线下打款申请" href="javascript:;"></a>\
                                           <a class="delete fa fa-trash fa-lg pull-left" title="删除订单" href="javascript:;"></a>';
		                       	   } else if (aData.offlineAudit == 3) {
//		                       		  operation = 
//				                		   '<a class="detail fa fa-bars fa-lg pull-left" title="详情" href="javascript:;"></a>\
//				                		   <a class="cancle fa fa-times-circle-o fa-lg pull-left" title="取消订单" href="javascript:;"></a>\
//			                       		   <a class="upload fa fa-upload fa-lg pull-left" title="上传线下打款凭证" href="javascript:;"></a>';
		                       		   operation = 
				                		   '<a class="detail fa fa-bars fa-lg pull-left" title="详情" href="javascript:;"></a>\
				                		   <a class="cancle fa fa-times-circle-o fa-lg pull-left" title="取消订单" href="javascript:;"></a>\
                                           <a class="delete fa fa-trash fa-lg pull-left" title="删除订单" href="javascript:;"></a>';
	                       		   }else{
	                       			   operation = 
	                       				   '<a class="detail fa fa-bars fa-lg pull-left" title="详情" href="javascript:;"></a>\
	                       				   <a class="cancle fa fa-times-circle-o fa-lg pull-left" title="取消订单" href="javascript:;"></a>\
                                           <a class="delete fa fa-trash fa-lg pull-left" title="删除订单" href="javascript:;"></a>';
	                       		   }
		                           break;
		                       case (3):
		                    	   formatState = "<center>已兑付</center>";
		                       	   operation = '<a class="detail fa fa-bars fa-lg pull-left" title="详情" href="javascript:;"></a>';
		                           break;
		                       case (4):
		                    	   formatState = "<center>部分支付</center>";
			                       operation = 
		                			   '<a class="detail fa fa-bars fa-lg pull-left" title="详情" href="javascript:;"></a>\
	                       			   <a class="upload fa fa-upload fa-lg pull-left" title="上传线下打款凭证" href="javascript:;"></a>';
		                    	   break;
		                       case (5):
		                    	   formatState = "<center>已取消</center>";
			                       operation = '<a class="detail fa fa-bars fa-lg pull-left" title="详情" href="javascript:;"></a>\
			                       <a class="delete fa fa-trash fa-lg pull-left" title="删除订单" href="javascript:;"></a>';
		                    	   break;
		                       case (6):
		                    	   formatState = "<center>已完成</center>";
			                       operation = 
		                			   '<a class="detail fa fa-bars fa-lg pull-left" title="详情" href="javascript:;"></a>';
		                    	   break;
		                       case (7):
		                    	   formatState = "<center>即将到期</center>";
			                       operation = 
		                			   '<a class="detail fa fa-bars fa-lg pull-left" title="详情" href="javascript:;"></a>';
		                    	   break;
		                       case (8):
		                    	   formatState = "<center>待兑付</center>";
			                       operation = 
		                			   '<a class="detail fa fa-bars fa-lg pull-left" title="详情" href="javascript:;"></a>\
		                			   <a class="redeem fa fa-mail-reply fa-lg pull-left" title="兑付" href="javascript:;"></a>';
		                    	   break;
		                       default:
		                    	   formatState = "<center>-</center>";
		                       	   operation = '<a class="detail fa fa-bars fa-lg pull-left" title="详情" href="javascript:;"></a>';
                	   }
//                	   $('td:eq(0)', nRow).html(orderId);
                	   $('td:eq(0)', nRow).html(contactNum);
                	   $('td:eq(1)', nRow).html(inverstor);
                	   $('td:eq(2)', nRow).html(productBriefName);
                	   $('td:eq(3)', nRow).html(orderAmount);
//                	   $('td:eq(4)', nRow).html(groupName);
                	   $('td:eq(4)', nRow).html(employee);
                	   $('td:eq(5)', nRow).html(orderTime);
                	   $('td:eq(6)', nRow).html(payTime);
                	   $('td:eq(7)', nRow).html(formatState);
                	   $('td:eq(8)', nRow).html(typeDes);
                	   $('td:eq(9)', nRow).html(operation);
                       return nRow;
                   },
                   "fnServerData" : function(ajaxSource, dataSet, fnCallback) {
	                   var json = "";
	                   var s;
	                   for (var i = 0; i < dataSet.length; i++) {
	                       s = dataSet[i];
	                   	   if (s.name == 'sEcho') {
	                   		   json = json + '"echo":' + s.value;
		                   } else if (s.name == 'iDisplayStart') {
		                	   json = json + ',"page":' + s.value;
		                   } else if (s.name == 'iDisplayLength') {
		                	   json = json + ',"pageSize":' + s.value;
		                   }
	                   }
	                   
	                   
	                   var orgId = $("#org_id").attr("value");
//	                   var s = $('#orderTimeStart').val();
//	                   var e =$ ('#orderTimeEnd').val();
//	                   if(s != '' && e != ''){
//	                	   var tmpS = s.split('-');
//		                   var tmpE = e.split('-');
//		                   var start = new Date();
//		                   var end = new Date();
//		                   start.setFullYear(tmpS[0]);
//		                   start.setMonth(tmpS[1]-1);
//		                   start.setDate(tmpS[2]+1);
//		                   end.setFullYear(tmpE[0]);
//		                   end.setMonth(tmpE[1]-1);
//		                   end.setDate(tmpE[2]+1);
//		                   if(start>end){
//		                	   bootbox.alert("下单开始时间不能大于下单结束时间");
//		                   }
//	                   }
	                   var form = $("form#queryForm").serializeJSON();
                   	   var js = form.replace('}', ',');
                   	   json = js + json +'}';
                       $.ajax({
                       	"contentType":"application/json; charset=UTF-8",
                           "dataType" : 'json',
                           "type" : "POST",
                           "url" : ajaxSource,
                           "data" : json,
                           "success" : fnCallback
                       });
                   },
                });
                //防止多次初始化
//                var oTableB = null;
//                var oTableCharge = null;
//                var oTableConmission = null;
                
                // 详情
                $('#ordersEditable').on("click", "a.detail", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[1].id;
                    window.location = ctx + '/orders/detail/' + id + '';  
                }));
                
                // 取消订单
                $('#ordersEditable').on("click", "a.cancle", (function (e) {
                    e.preventDefault();
                    
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    json = "{" + '"id":"' + id + '"}';
    	            swal({
    	                title: "确认取消订单?",
    	                text: "你将会取消此订单！",
    	                type: "warning",
    	                showCancelButton: true,
    	                confirmButtonColor: "#DD6B55",
    	                confirmButtonText: "确认",
    	                cancelButtonText: "取消",
    	                closeOnConfirm: false,
    	                closeOnCancel: false
    	            }, function (isConfirm) {
    	            	if (isConfirm) {
    	            		$.ajax({
                               	   contentType:"application/json; charset=UTF-8",
                                   dataType : 'json',
                                   type : "POST",
                                   url : ctx + "/orders/cancle",
                                   data : json,
                                   success : function(msg){
                                	   swal("已取消", "", "success");
                                	   oTable.fnDraw(false);
                                   },
    	            				error: function (msg) {
    	            					bootbox.alert(msg.message);
    	            					swal("操作错误", "", "error");
    	            			   }
                               });
    	            	}else{
    	            		swal("未取消", "", "error");
    	            	}
    	            });
                }));
                
                // 删除订单
                $('#ordersEditable').on("click", "a.delete", (function (e) {
                    e.preventDefault();
                    
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    json = "{" + '"id":"' + id + '"}';
                    swal({
                        title: "确认删除订单?",
                        text: "你将会删除此订单！",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确认",
                        cancelButtonText: "取消",
                        closeOnConfirm: false,
                        closeOnCancel: false
                    }, function (isConfirm) {
                        if (isConfirm) {
                            $.ajax({
                                   contentType:"application/json; charset=UTF-8",
                                   dataType : 'json',
                                   type : "POST",
                                   url : ctx + "/orders/delete",
                                   data : json,
                                   success : function(msg){
                                       swal("已删除", "", "success");
                                       oTable.fnDraw(false);
                                   },
                                    error: function (msg) {
                                        bootbox.alert(msg.message);
                                        swal("操作失败", "", "error");
                                   }
                               });
                        }else{
                            swal("未删除", "", "error");
                        }
                    });
                }));
                
                // 上传线下支付凭证
                $('#ordersEditable').on("click", "a.upload", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    var uploaded = nRow.children[2].id;
                    json = "{" + '"id":"' + id + '"}';
                    var modal = $('#uploadModal').modal('show');
                    $('#orderUploadId').val(id);
                    if(uploaded == 'true'){
                    	$('#upload').css('display','none');
                    }else{
                    	$('#uploaded').css('display','none');
                    }
                }));
                
                // 其他支付方式申请开通审核
                $('#ordersEditable').on("click", "a.offlineAudit", (function (e) {
                    e.preventDefault();
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[1].id;
                    $.ajax({
                    	type:"post",
                        url: ctx + "/orders/offlinePayAudit",
                        data:"id=" + id,
                        dataType:"json",
                        success: function(msg){
                        	$("#auditBody").empty();
                        	var tmpl = $("#auditTemplate").tmpl(msg.data).appendTo("#auditBody");
                        	var modal = $('#offlineAuditMomal').modal('show');
                        	modal.on("hidden.bs.modal",function(e){
                        		$(this).removeData();
                        		$("#auditBody").empty();
                        	});
                        	$('#auditBtn').click(function(){
                        		var json = $("form#auditForm").serializeJSON();
                        		$.ajax({
                        			"contentType":"application/json; charset=UTF-8",
                                	type:"post",
                                    url: ctx + "/orders/offlineApplyAudit",
                                    data: json,
                                    dataType:"json",
                                    success: function(msg){
                                    	if(msg.code == 1){
                                    		bootbox.alert("操作成功");
                                    		$('#offlineAuditMomal').modal('hide');
                                    		oTable.fnClearTable();
                                    	}else{
                                    		bootbox.alert(msg.message);
                                    		$('#offlineAuditMomal').modal('hide');
                                    	}
                                    },
                                    error: function (msg) {
                                    	bootbox.alert(msg.message);
                                    	$('#offlineAuditMomal').modal('hide');
                                    }
                                });
                            });
                        },
                        error: function (msg) {
                        	bootbox.alert(msg.message);
                        }
                    });
                    
                }));
                
//                //模拟完成订单
//                $('#ordersEditable').on("click", "a.complete", (function (e) {
//                    e.preventDefault();
//                    var nRow = $(this).parents('tr')[0];
//                    var id = nRow.children[0].id;
//                    json = "{" + '"id":"' + id + '"}';
//    	            swal({
//    	                title: "确认完成订单?",
//    	                text: "完成此订单！",
//    	                type: "warning",
//    	                showCancelButton: true,
//    	                confirmButtonColor: "#DD6B55",
//    	                confirmButtonText: "确认",
//    	                cancelButtonText: "取消",
//    	                closeOnConfirm: false,
//    	                closeOnCancel: false
//    	            }, function (isConfirm) {
//    	            	if (isConfirm) {
//    	            		$.ajax({
//                               	   contentType:"application/json; charset=UTF-8",
//                                   dataType : 'json',
//                                   type : "POST",
//                                   url : ctx + "/orders/complete",
//                                   data : json,
//                                   success : function(msg){
//                                	   swal("订单已完成", "", "success");
//                                	   oTable.fnDraw(false)
//                                   },
//    	            				error: function (msg) {
//    	            					bootbox.alert(msg.message);
//    	            					swal("操作错误", "", "error");
//    	            			   }
//                               });
//    	            	}else{
//    	            		swal("未完成", "", "error");
//    	            	}
//    	            });
//                }));
                
                // 赎回
                $('#ordersEditable').on("click", "a.redeem", (function (e) {
                    e.preventDefault();
                    
                    var nRow = $(this).parents('tr')[0];
                    var id = nRow.children[0].id;
                    json = "{" + '"id":"' + id + '"}';
    	            swal({
    	                title: "确认赎回订单?",
    	                text: "赎回此订单！",
    	                type: "warning",
    	                showCancelButton: true,
    	                confirmButtonColor: "#DD6B55",
    	                confirmButtonText: "确认",
    	                cancelButtonText: "取消",
    	                closeOnConfirm: false,
    	                closeOnCancel: false
    	            }, function (isConfirm) {
    	            	if (isConfirm) {
    	            		$.ajax({
                               	   contentType:"application/json; charset=UTF-8",
                                   dataType : 'json',
                                   type : "POST",
                                   url : ctx + "/orders/redeem",
                                   data : json,
                                   success : function(msg){
                                	   swal("已赎回", "", "success");
                                	   oTable.fnDraw(false)
                                   },
    	            				error: function (msg) {
    	            					bootbox.alert(msg.message);
    	            					swal("操作错误", "", "error");
    	            			   }
                               });
    	            	}else{
    	            		swal("未赎回", "", "error");
    	            	}
    	            });
                }));
                
                //重置查询
                $('#cancleQuery').click(function(){
                	$('#groupId').val(null);
                	//重置按钮 清空datepicker缓存
                	$('#orderTimeStart').datepicker('setDate', null);
                	$('#orderTimeEnd').datepicker('setDate', null);
                });
                
                //查询
                $('#queryBtn').click(function(){
                	oTable.fnClearTable();
                });
                
                var resetUploadTip = function() {
                	$('#upload').css('display','block');
                	$('#uploaded').css('display','block');
                }

                Dropzone.options.myAwesomeDropzone = { 
                    	url: ctx+ "/orders/imgUploads", 
                    	autoProcessQueue: false,
                        uploadMultiple: true,
                        paramName:"file",
                        maxFiles: 5,
                        addRemoveLinks: true,
                        parallelUploads:5,
                        dictRemoveFile: "删除文件",
                        dictDefaultMessage: "<center>单击或拖拽图片至此灰色区域</center>",
                        dictMaxFilesExceeded: "您不能在上传更多的图片了.",
                    	acceptedFiles: ".jpg,.png,.jpeg,.gif,.bmp" ,
                    	
                    	init: function() {
                            var myDropzone = this;
                            $(function () { $('#uploadModal').on('hidden.bs.modal', function () {
                            	myDropzone.removeAllFiles(true);
                            	 })
                             });
                            this.on("sendingmultiple", function() {
                            });
                            this.on("successmultiple", function(files, response) {
                            });
                            this.on("errormultiple", function(files, response) {
                            });
                            this.on("maxfilesexceeded", function(files) {
                            	bootbox.alert("已超过最大图片数量限制！");
                                 myDropzone.removeFile(files);
                            });
                            myDropzone.on("sending", function(file, xhr, formData) {
//                            	formData.romove("id");
                                formData.append("id", $('#orderUploadId').val());
                            });
//                            this.on("addedfile",function(files,response){
//                            });
                            this.on("success", function(file,message) {
                            	if(0 == message.code){
                            		swal(message.message, "", "error");
                            		var modal = $('#uploadModal').modal('hide');
                            	}else{
                            		swal("上传成功", "", "success");
                                	myDropzone.removeAllFiles(true);
                            		var modal = $('#uploadModal').modal('hide');
                            	}
                        		resetUploadTip();
//                        		oTable.fnClearTable();
                            });
                            this.element.parentNode.parentNode.nextElementSibling.querySelector("button[type=submit]").addEventListener("click", function(e) {
                                e.preventDefault();
                                e.stopPropagation();
                                if(myDropzone.files.length == 0){
                                	bootbox.alert("文件不能为空");
                                }else{
                                	if($('#upload').css('display') == 'none'){
                                		bootbox.confirm({  
                                            buttons: {  
                                                confirm: {  
                                                    label: '确认上传',  
                                                    className: 'btn-primary'  
                                                },  
                                                cancel: {  
                                                    label: '取消上传',  
                                                    className: 'btn-default'  
                                                }  
                                            },  
                                            message: "请确认已添加所有所需凭证，上传将会覆盖原先的打款凭证", 
                                            callback: function(result) {  
                                                if(result) {  
                                                	myDropzone.processQueue();  
                                                } else {  
                                                }  
                                            },  
                                            title: "温馨提示：",
                                            });
                                	}else{
                                		bootbox.confirm({  
                                            buttons: {  
                                                confirm: {  
                                                    label: '确认上传',  
                                                    className: 'btn-primary'  
                                                },  
                                                cancel: {  
                                                    label: '取消上传',  
                                                    className: 'btn-default'  
                                                }  
                                            },  
                                            message: "请确认已添加所有所需凭证", 
                                            callback: function(result) {  
                                                if(result) {  
                                                	myDropzone.processQueue();  
                                                } else {  
                                                }  
                                            },  
                                            title: "温馨提示：",
                                            });
                                	}
                                }
                            });
                            this.element.parentNode.parentNode.nextElementSibling.querySelector("button[type=button]").addEventListener("click", function(e) {
//                                e.preventDefault();
//                                e.stopPropagation();
//                                myDropzone.processQueue();
                                myDropzone.removeAllFiles(true);
                                resetUploadTip();
                            });
                            this.element.parentNode.parentNode.parentNode.childNodes[1].childNodes[1].addEventListener("click", function(e) {
//                              e.preventDefault();
//                              e.stopPropagation();
//                              myDropzone.processQueue();
                              myDropzone.removeAllFiles(true);
                              resetUploadTip();
                            });
                    	}
                }
            }

        };

    }();
    
    return {
        init: function () {
        	editable.init();
        	handleEmployeeTree();
        }
    };
}();
